<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<style>
    body::-webkit-scrollbar {width: 0;}
    .shenren{display: none}
    .ctmsg{padding-left: 150px;color: #777}
</style>

<body>
<form class="layui-form layui-form-pane" id="operatePage">
    <div class="page-title"><div class="page-title-con"><span>编辑开始流程</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">
        <div class="block-first">
            <div class="block-first">
                <div class="layui-form-item">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <label class="layui-form-label"><text>*</text>流程名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="name" id="name" value="开始流程" placeholder="请输入" readonly autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <label class="layui-form-label">可见对象</label>
                            <div class="layui-input-block">
                                <div class="radio-block" id="shentypeDiv"></div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item shenren" id="shentype_user">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <label class="layui-form-label">用户</label>
                            <div class="layui-input-block relative">
                                <div class="tanxian">
                                    <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=userid&type=user&single=2');"></div>
                                    <div class="tanxiannei" id="userid"></div>
                                </div>
                                <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=userid&type=user&single=2');"><i class="layui-icon layui-icon-search"></i></div></div>
                                <div id="userid_tanerror" class="tanerrormsg"></div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item shenren" id="shentype_role">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <label class="layui-form-label">角色</label>
                            <div class="layui-input-block">
                                <div id="roleid"></div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item shenren" id="shentype_dept">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <label class="layui-form-label">部门</label>
                            <div class="layui-input-block relative">
                                <div class="tanxian">
                                    <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=deptid&type=dept&single=2');"></div>
                                    <div class="tanxiannei" id="deptid"></div>
                                </div>
                                <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=deptid&type=dept&single=2');"><i class="layui-icon layui-icon-search"></i></div></div>
                                <div id="deptid_tanerror" class="tanerrormsg"></div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item shenren" id="shentype_gang">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <label class="layui-form-label">岗位</label>
                            <div class="layui-input-block">
                                <div id="gangid"></div>
                            </div>
                        </div>
                    </div>
                </div>




                <div class="layui-form-item">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <label class="layui-form-label"><text>*</text>是否需要预审</label>
                            <div class="layui-input-block">
                                <div class="radio-block" id="isadvanDiv"></div>
                            </div>
                        </div>
                    </div>
                </div>


                <div class="layui-form-item">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <label class="layui-form-label">审批通过通知谁?</label>
                            <div class="layui-input-block relative">
                                <div class="tanxian">
                                    <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=tonger&type=user&single=2');"></div>
                                    <div class="tanxiannei" id="tonger"></div>
                                </div>
                                <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=tonger&type=user&single=2');"><i class="layui-icon layui-icon-search"></i></div></div>
                            </div>
                        </div>
                    </div>
                </div>


                <div class="layui-form-item">
                    <div class="layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <label class="layui-form-label"><text>*</text>流程类型</label>
                            <div class="layui-input-block">
                                <div class="radio-block" id="coursetypeDiv"></div>
                            </div>
                            <div class="ctmsg"></div>
                        </div>

                    </div>
                </div>


            </div>
        </div>
    </div>
</form>
<script>
    var param_sectionnum = getQueryVariable('sectionnum');
    var param_name = getQueryVariable('name') || '';
    param_name = decodeURI(param_name);
    $("#name").val(param_name)


    layui.use(['laytp', 'form', 'table'], function() {
        var form = layui.form, layer = layui.layer,table = layui.table;

        var isadvan = 0;
        var coursetype = 0;
        var users = '';
        var param_domvalue = $('section[key="'+param_sectionnum+'"] .nonedata', parent.document).text() || '';
        if(param_domvalue){
            var valueObj = JSON.parse(param_domvalue);
            users = valueObj.users || '';
            valueObj.shentype = valueObj.shentype || ''
            isadvan = valueObj.isadvan || 0;
            coursetype = valueObj.coursetype || 0;
            tonger = valueObj.tonger || '';
        }
        facade.ajax({type: 'get', url: ask_flow_start_class_assist,data:{
            users:users,
            tonger:tonger,
            shentype:valueObj.shentype
        }}).done(function(res){
            if (res.code === 2000) {
                var data = res.data;
                if(data.users_info.length > 0){
                    tan_tags_init('#users', data.users_info)
                }

                if(data.tonger_info.length > 0){
                    tan_tags_init('#tonger', data.tonger_info);
                }


                var shentype_str = '';
                shentype = res.data.shentype;
                for (var key in shentype){
                    if(valueObj.shentype == key){
                        shentype_str += '<input type="radio" name="shentype" value="'+key+'" lay-filter="shentype" title="'+shentype[key]+'" checked>';
                    }else{
                        shentype_str += '<input type="radio" name="shentype" value="'+key+'" lay-filter="shentype" title="'+shentype[key]+'">';
                    }

                }
                $('#shentypeDiv').html(shentype_str);


                if(valueObj.shentype == 'user'){
                    if(data.users_info.length > 0){
                        tan_tags_init('#userid', data.users_info);
                    }
                }
                if(valueObj.shentype == 'dept'){
                    if(data.users_info.length > 0){
                        tan_tags_init('#deptid', data.users_info);
                    }
                }
                var edit_roleid = '';
                if(valueObj.shentype == 'role'){
                    edit_roleid = data.users_info;
                }
                var edit_gangid = '';
                if(valueObj.shentype == 'gang'){
                    edit_gangid = data.users_info;
                }

                $("#shentype_"+valueObj.shentype).show();



                var roleidXmObj = xmselect_duo('roleid', res.data.roleArr, edit_roleid, function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#roleid").find('xm-select').removeClass('error');
                    }else{
                        $("#roleid").find('xm-select').addClass('error');
                    }
                });

                var gangidXmObj = xmselect_duo('gangid', res.data.gangArr, edit_gangid, function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#gangid").find('xm-select').removeClass('error');
                    }else{
                        $("#gangid").find('xm-select').addClass('error');
                    }
                });







                var isadvan_str = '';
                if(valueObj.isadvan == 1){
                    isadvan_str += '<input type="radio" name="isadvan" value="1" title="是" checked>';
                    isadvan_str += '<input type="radio" name="isadvan" value="0" title="否">';
                }else{
                    isadvan_str += '<input type="radio" name="isadvan" value="1" title="是">';
                    isadvan_str += '<input type="radio" name="isadvan" value="0" title="否" checked>';
                }
                $('#isadvanDiv').html(isadvan_str);



                var coursetype_str = '';
                if(valueObj.coursetype == 1){
                    coursetype_str += '<input type="radio" name="coursetype" value="0" title="固定流程">';
                    coursetype_str += '<input type="radio" name="coursetype" value="1" title="自由流程" checked>';
                }else{
                    coursetype_str += '<input type="radio" name="coursetype" value="0" title="固定流程" checked>';
                    coursetype_str += '<input type="radio" name="coursetype" value="1" title="自由流程">';
                }
                $('#coursetypeDiv').html(coursetype_str);



                render_from();
            }
        });


        form.on('radio(shentype)',function (data) {
            for (var key in shentype){
                $("#shentype_"+key).hide();
            }
            $("#shentype_"+data.value).show();
        });



        form.on('submit(add)', function(data){
            data.field.tonger = tan_tags_getvalue("#tonger", 'user');
            data.field.userid = tan_tags_getvalue("#userid", 'user');
            data.field.deptid = tan_tags_getvalue("#deptid", 'dept');

            data.field.users = '';
            if(data.field.shentype == 'user'){
                data.field.users = data.field.userid;
                var userid_name = tan_tags_getname("#userid", 'user');
                data.field.userid_name = '用户（'+userid_name+'）';
            }else if(data.field.shentype == 'dept'){
                data.field.users = data.field.deptid;
                var userid_name = tan_tags_getname("#deptid", 'dept');
                data.field.userid_name = '部门（'+userid_name+'）';
            }else if(data.field.shentype == 'role'){
                data.field.users = data.field.roleid;
                var userid_name = $("#roleid").find('.label-content').attr('title');
                data.field.userid_name = '角色（'+userid_name+'）';
            }else if(data.field.shentype == 'gang'){
                data.field.users = data.field.gangid;
                var userid_name = $("#gangid").find('.label-content').attr('title');
                data.field.userid_name = '岗位（'+userid_name+'）';
            }else{
                data.field.userid_name = '全部用户';
            }

            var namedata = '';
            var isadvan_name = data.field.isadvan > 0 ? '是' : '否';
            var coursetype_name = data.field.coursetype > 0 ? '自由流程' : '固定流程';
            var tonger_name = data.field.tonger ? '已设置' : '未设置';
            namedata += '<p>可见对象：'+data.field.userid_name+'</p>';
            namedata += '<p>是否预审：'+isadvan_name+'</p>';
            namedata += '<p>通知人：'+tonger_name+'</p>';
            namedata += '<p>流程类型：'+coursetype_name+'</p>';


            if(data.field.coursetype > 0){
                window.parent.set_gaikuai(true);
            }else{
                window.parent.set_gaikuai(false);
            }


            var datastr = JSON.stringify({
                users:data.field.users,
                shentype:data.field.shentype,
                isadvan:data.field.isadvan,
                tonger:data.field.tonger,
                coursetype:data.field.coursetype,
            });

            $('section[key="'+param_sectionnum+'"] .nonedata', parent.document).text(datastr);
            $('section[key="'+param_sectionnum+'"] .namedata', parent.document).html(namedata);
            layer_close();
            return false;
        });

    });



</script>
</body>
</html>
